package ro.sergiu.finder.filters;

import java.beans.Beans;
import ro.sergiu.finder.utils.NumericDocument;

/**
 *
 * @author Toporjinschi
 * @param <M> the type of verification item (ex. String if is a db connection, class if is a bean
 * search)
 */
public class FloatFilter<M> extends FilterPanelUI<M, Float> {

    public FloatFilter(String title, M mappingItem, Operator operator) {
        super(title, mappingItem, operator);
        initComponents();
    }

    /**
     * This constructor should be used only by de IDE. Calling this will throw
     * {@link IllegalAccessException}
     */
    public FloatFilter() {
        if (!Beans.isDesignTime()) {
            throw new IllegalArgumentException("Illegal call of constructor " + this.getClass().getName() + ". Should be used only in design time.");
        }
        initComponents();
    }

    @Override
    public Float getValue() {
        return Float.parseFloat(value.getText());
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        value = new javax.swing.JTextField();

        setToolTipText("");
        setMaximumSize(new java.awt.Dimension(150, 45));
        setMinimumSize(new java.awt.Dimension(150, 45));
        setName(""); // NOI18N
        setPreferredSize(new java.awt.Dimension(150, 45));
        setLayout(new java.awt.BorderLayout());

        value.setDocument(NumericDocument.FLOAT);
        value.setToolTipText("");
        add(value, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JTextField value;
    // End of variables declaration//GEN-END:variables

    @Override
    public String toString() {
        return this.getMappingItem() + " " + this.getOperator() + " " + this.getValue();
    }

}
